package com.hrma.services.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.hrma.dao.AdminMapper;
import com.hrma.dao.EmployeeMapper;
import com.hrma.entity.Admin;
import com.hrma.entity.AdminDTO;
import com.hrma.services.AdminService;
import org.springframework.stereotype.Service;

@Service
public class AdminImpl implements AdminService {
    private final AdminMapper adminMapper;
    private final EmployeeMapper employeeMapper;

    public AdminImpl(AdminMapper adminMapper, EmployeeMapper employeeMapper) {
        this.adminMapper = adminMapper;
        this.employeeMapper = employeeMapper;
    }

    @Override
    public void add(String num) {
        if(employeeMapper.exist(null,num)){
            adminMapper.add(employeeMapper.getIdByNum(num));
        }else {
            throw new RuntimeException("没有该编号的员工!");
        }
    }

    @Override
    public void delete(Integer id) {
        adminMapper.delete(id);
    }

    @Override
    public Page<Admin> getList(AdminDTO data) {
        PageHelper.startPage(data.getPageNum(),data.getPageSize());
        return adminMapper.getList(data);
    }
}
